package eclipse;

import java.util.Arrays;
import java.util.Random;


public class ArrayExercise03 {
    public static void main(String[] args) {
        int[] a = suiji();
        System.out.println(Arrays.toString(a));
        System.out.println("-----------------");
        sort(a);
        System.out.println("------------------");
        System.out.println(Arrays.toString(a));

    }

    private static void sort(int[] a) {
        for(int i = 0; i < a.length; i++){
            for(int j = i + 1; j < a.length; j++) {
                if (a[i] > a[j]){
                    int swap = a[i];
                    a[i] = a[j];
                    a[j] = swap;
                }

            }
        }
    }

    private static int[] suiji() {
         /*
        1. 产生范围5+[0, 6)范围的随机长度
        存到变量len
        2. 新建len长度int[]数组
        存到变量a
        3.遍历数组,填入100内随机值
        4.返回数组a
         */
        int len = 5 + new Random().nextInt(7);
        int[] arr = new int[len];
        for(int i = 0; i < arr.length; i++){
            arr[i] = new Random().nextInt(100);
        }
        return arr;
    }
}
